package com.grandbroad.eim.ui.fragment.live;

import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.grandbroad.eim.adapter.ChatListAdapter;
import com.grandbroad.eim.base.BaseFragment;
import com.grandbroad.eim.base.BaseRecyclerview;

import java.util.List;

import cn.jpush.im.android.api.event.ChatRoomMessageEvent;
import cn.jpush.im.android.api.model.Message;

public class ChatRoomFragment extends BaseRecyclerview {
    private ChatListAdapter listAdapter;
    @Override
    protected void initRecyclerview(RecyclerView recyclerView) {
        //设置聊天室背景颜色
        recyclerView.setBackgroundColor(Color.parseColor("#e8e8e9"));
        listAdapter = new ChatListAdapter();
        recyclerView.setAdapter(listAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    }



    @Override
    protected void loadData() {

    }

    /***
     * 接受聊天室的消息
     * @param event
     */
    public void onEventMainThread(ChatRoomMessageEvent event) {
        Log.d("tag", "ChatRoomMessageEvent received .");
        List<Message> msgs = event.getMessages();
        /*
        for (Message msg : msgs) {
            //这个页面仅仅展示聊天室会话的消息
           // postMessageToDisplay("MessageReceived", event.getResponseCode(), event.getResponseDesc(), msg);
        }
        */
        listAdapter.setMessageList(msgs);
        listAdapter.notifyDataSetChanged();

    }


}
